package com.example.myapplication.request

import androidx.lifecycle.MutableLiveData
import com.example.myapplication.bean.ListResultBean
import com.example.myapplication.bean.article.ArticleBean
import com.example.myapplication.bean.article.BannerBean
import com.kun.base.net.Api
import com.kun.base.net.ResponseResult

/**
 *文章相关接口请求
 *
 * @author : Kun
 * @date : 2021/5/18 18:06
 */
class ArticleRequest {
    /**
     * 文章接口返回的结果
     */
    val articleResult = MutableLiveData<ResponseResult<ListResultBean<ArticleBean>>>()

    /**
     * banner接口返回的结果
     */
    val bannerListResult = MutableLiveData<ResponseResult<List<BannerBean>>>()

    /**
     * 置顶文章
     */
    val topArticleResult = MutableLiveData<ResponseResult<List<ArticleBean>>>()

    /**
     * 请求文章数据
     */
    suspend fun requestArticleList(index: Int) {
        val res = Api.apiCall {
            Api.getInstance(IApi::class.java).getArticleList(index)
        }
        articleResult.postValue(res)
    }

    /**
     * 请求banner数据
     */
    suspend fun requestBannerList() {
        bannerListResult.value = Api.apiCall {
            Api.getInstance(IApi::class.java).getBannerList()
        }
    }

    /**
     * 请求置顶文章数据
     */
    suspend fun requestTopArticleList() {
        topArticleResult.value = Api.apiCall {
            Api.getInstance(IApi::class.java).getTopArticleList()
        }
    }
}